package com.kaigejava.juc.volatitle;

/**
 * @author kaigejava
 * 单线程下懒汉式的单例
 */
public class SingletonDemo1 {
    private static SingletonDemo1 singletonDemo1 = null;
    private  SingletonDemo1(){
        System.out.println("======开始调用私有构造器了。线程名称："+Thread.currentThread().getName());
    }
    public  static SingletonDemo1 getInstance(){
        if(null == singletonDemo1){
            singletonDemo1 = new SingletonDemo1();
        }
        return singletonDemo1;
    }
    public static void main(String[] args) {
        System.out.println(SingletonDemo1.getInstance()== SingletonDemo1.getInstance());
        System.out.println(SingletonDemo1.getInstance()== SingletonDemo1.getInstance());
    }
}
